Repository navigation
Salt notice: detection-only, dismissible, links to docs - #14
Conversation
Remove all salt generation and the in-plugin fix wizard. The plugin no longer generates salts, reads or scans wp-config.php, or offers a "Fix it for me" path — WordPress already ships a generator, and rewriting or parsing the site's master config is too high blast-radius for a login plugin. Keep weak-salt detection (runtime constants are authoritative) and rework the admin notice: link to the docs guide (DOCS_SALTS_URL) rather than api.wordpress.org directly, drop the "Fix it for me" button, and make it site-wide dismissible. One admin dismissing hides it for all, persisted in the magicauth_salt_notice_dismissed site option and re-armed by check_salts() if salts ever regress to weak. Removed: - Installer: generate_salt_value / salt_values / generate_salt_block, recheck_salts_from_file, config_has_weak_salts / define_pattern, locate_wp_config / filesystem - Settings: ajax_fix_salts + its wp_ajax registration, and the "Fix WordPress salts" diagnostics card - admin JS: initSaltFix() wizard, plus orphaned wizard CSS - tests: SaltFixTest (exercised the now-removed methods) Token and login-code generation are untouched; the informed-consent gate on the branded-login toggle is unchanged. Version stays 1.0.0.
📝 WalkthroughWalkthroughThe PR removes the automatic "Fix WordPress salts" wizard and replaces it with a simpler dismissible admin notice. This involves removing wizard handlers, UI, and JavaScript; implementing weak-salt notice dismissal via AJAX; registering the new handler; and removing related test coverage. ChangesReplace salt-fix wizard with dismissible notice
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@includes/Installer.php`:
- Around line 237-289: The site-wide salt warning rendered by
Installer::render_salt_notice() is suppressed on the MagicAuth settings page
because Settings::suppress_foreign_notices() removes all admin_notices on
settings_page_magicauth; to fix, either update suppress_foreign_notices() to
skip/remain notices that include a unique marker (e.g.
data-magicauth-salt-notice or a specific CSS class like magicauth-salt-notice)
so render_salt_notice() still runs on that admin screen, or change
render_salt_notice() to detect the current admin page (settings_page_magicauth)
and output an inline version of the same dismissible notice there (preserving
the nonce, AJAX route magicauth_dismiss_salt_notice and data attributes) so
admins can see/dismiss it on the settings page.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ec5a1582-e6c9-465c-9ed1-4ef40820b359
📒 Files selected for processing (6)
assets/css/magicauth-admin.cssassets/js/magicauth-admin.jsincludes/Admin/Settings.phpincludes/Installer.phpincludes/Plugin.phptests/phpunit/Model/SaltFixTest.php
💤 Files with no reviewable changes (3)
- tests/phpunit/Model/SaltFixTest.php
- assets/css/magicauth-admin.css
- assets/js/magicauth-admin.js
| /** | ||
| * Admin notice for weak salts. Shown to manage_options users on every admin | ||
| * screen until the salts are fixed or an admin dismisses it. MagicAuth does | ||
| * not generate salts or edit wp-config.php; the notice points to the docs, | ||
| * where the fix is "generate at api.wordpress.org, paste into wp-config.php, | ||
| * reload". Dismissal is site-wide (one option) and persisted via the AJAX | ||
| * handler below; check_salts() re-arms it if salts ever regress. The notice | ||
| * carries a small self-contained dismiss script because it renders on admin | ||
| * screens where magicauth-admin.js is not enqueued. | ||
| */ | ||
| public static function render_salt_notice(): void { | ||
| if ( ! self::has_weak_salts() ) { | ||
| return; | ||
| } | ||
| if ( get_option( self::SALT_NOTICE_DISMISSED_OPTION ) ) { | ||
| return; | ||
| } | ||
| if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ) { | ||
| return; | ||
| } | ||
| $fix_url = add_query_arg( | ||
| [ | ||
| 'page' => 'magicauth', | ||
| 'magicauth-fix-salts' => '1', | ||
| ], | ||
| admin_url( 'options-general.php' ) | ||
| ); | ||
| $nonce = wp_create_nonce( self::SALT_NOTICE_DISMISS_NONCE ); | ||
| ?> | ||
| <div class="notice notice-warning"> | ||
| <div class="notice notice-warning is-dismissible magicauth-salt-notice" | ||
| data-magicauth-salt-notice | ||
| data-nonce="<?php echo esc_attr( $nonce ); ?>" | ||
| data-ajaxurl="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>"> | ||
| <p> | ||
| <strong><?php esc_html_e( 'MagicAuth: weak WordPress salts detected.', 'magicauth' ); ?></strong> | ||
| <?php esc_html_e( 'Your security keys still hold placeholder or empty values, so token and session secrets are not unique to this site. Your magic links stay safe (each carries its own random secret), but fixing this is recommended — especially before turning on the branded login replacement.', 'magicauth' ); ?> | ||
| </p> | ||
| <p> | ||
| <a href="<?php echo esc_url( $fix_url ); ?>" class="button button-primary"><?php esc_html_e( 'Fix it for me', 'magicauth' ); ?></a> | ||
| <?php | ||
| echo ' '; | ||
| echo wp_kses( | ||
| sprintf( | ||
| /* translators: 1: documentation guide URL, 2: salt generator URL */ | ||
| __( 'Read the <a href="%1$s" target="_blank" rel="noopener">step-by-step guide</a>, or generate fresh salts at <a href="%2$s" target="_blank" rel="noopener">api.wordpress.org/secret-key</a> and paste them into <code>wp-config.php</code>.', 'magicauth' ), | ||
| esc_url( self::DOCS_SALTS_URL ), | ||
| 'https://api.wordpress.org/secret-key/1.1/salt/' | ||
| ), | ||
| [ | ||
| 'a' => [ | ||
| 'href' => true, | ||
| 'target' => true, | ||
| 'rel' => true, | ||
| ], | ||
| 'code' => [], | ||
| ] | ||
| ); | ||
| ?> | ||
| <a href="<?php echo esc_url( self::DOCS_SALTS_URL ); ?>" class="button button-primary" target="_blank" rel="noopener"><?php esc_html_e( 'Learn how to fix this', 'magicauth' ); ?></a> | ||
| </p> | ||
| </div> | ||
| <script> | ||
| ( function () { | ||
| document.addEventListener( 'click', function ( ev ) { | ||
| var dismiss = ev.target.closest ? ev.target.closest( '.notice-dismiss' ) : null; | ||
| if ( ! dismiss ) { return; } | ||
| var notice = dismiss.closest( '[data-magicauth-salt-notice]' ); | ||
| if ( ! notice ) { return; } | ||
| fetch( notice.getAttribute( 'data-ajaxurl' ), { | ||
| method: 'POST', | ||
| credentials: 'same-origin', | ||
| headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
| body: new URLSearchParams( { | ||
| action: 'magicauth_dismiss_salt_notice', | ||
| _ajax_nonce: notice.getAttribute( 'data-nonce' ) | ||
| } ) | ||
| } ); | ||
| } ); | ||
| } )(); | ||
| </script> |
There was a problem hiding this comment.
This notice is suppressed on the MagicAuth settings screen.
Settings::suppress_foreign_notices() removes all admin_notices callbacks on settings_page_magicauth, so this "site-wide" notice never renders on the page where admins are most likely to fix or dismiss it. That leaves only the inline branding tooltip there, with no dismiss control. Please either exempt MagicAuth’s own notices from that suppression or render this notice inline on the settings page too.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@includes/Installer.php` around lines 237 - 289, The site-wide salt warning
rendered by Installer::render_salt_notice() is suppressed on the MagicAuth
settings page because Settings::suppress_foreign_notices() removes all
admin_notices on settings_page_magicauth; to fix, either update
suppress_foreign_notices() to skip/remain notices that include a unique marker
(e.g. data-magicauth-salt-notice or a specific CSS class like
magicauth-salt-notice) so render_salt_notice() still runs on that admin screen,
or change render_salt_notice() to detect the current admin page
(settings_page_magicauth) and output an inline version of the same dismissible
notice there (preserving the nonce, AJAX route magicauth_dismiss_salt_notice and
data attributes) so admins can see/dismiss it on the settings page.
What
Reworks the weak-salt handling to be detection-only. Removes all salt generation and the in-plugin fix wizard; keeps detection and turns the admin notice into a site-wide dismissible advisory that links to the docs.
Why
A login plugin should not be in the business of minting the site's master secrets or rewriting/parsing
wp-config.php. WordPress already ships a salt generator atapi.wordpress.org/secret-key. The 1.0.0 auto-write was already removed; this removes the interim copy-paste wizard (local generation + file-scan recheck) too, leaving a purely advisory contract.Changes
generate_salt_value/salt_values/generate_salt_block,recheck_salts_from_file,config_has_weak_salts/define_pattern,locate_wp_config/filesystem. Reworkedrender_salt_notice()to a single "Learn how to fix this" link →DOCS_SALTS_URL,is-dismissible, with a self-contained dismiss script (the notice renders on screens where the admin bundle isn't enqueued). Addedajax_dismiss_salt_notice();check_salts()re-arms the dismissal if salts ever regress.ajax_fix_salts()+ its registration and the "Fix WordPress salts" diagnostics card. Informed-consent gate on the branded-login toggle is unchanged.initSaltFix()and orphaned wizard styles.SaltFixTest(exercised the removed methods).Dismissal model
Site-wide, not per-user: one admin dismissing sets the
magicauth_salt_notice_dismissedsite option and hides the notice for everyone;check_salts()clears it when salts test strong, so a future regression re-arms it.Out of scope / untouched
Token and login-code generation (
TokenManager,Crockford) are not touched. Version stays 1.0.0.Verification
php -lon all changed PHP,node --checkon the admin JS and the inline dismiss script, a reflection surface check (removed methods gone, kept methods present), and a grep sweep for dangling references — all clean. PHPUnit/PHPStan run in CI.Summary by CodeRabbit